package com.bauer.os.frame.action;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class LoginController {

	@RequestMapping("/doLogin")
	public String doLogin(@RequestParam("userName") String userName, @RequestParam("password") String password) {
		System.out.println("123");
		Subject subject = SecurityUtils.getSubject();
		if(subject.isAuthenticated()){
			subject.logout();
		}
		AuthenticationToken token = new UsernamePasswordToken(userName, password);
		try {
			subject.login(token);
		} catch (AuthenticationException e) {
			e.printStackTrace();
			return "login";
		}
		return "main";
	}

	@RequestMapping("/login")
	public String login() {
		System.out.println("123");
		return "login";
	}
}
